package demo3;

import java.awt.*;

class Animal{
    public String name;
    //构造方法
    public Animal(String name){
        this.name = name;
    }
    //每个动物都会吃东西
    public void eat(){
        System.out.println(this.name + "正在吃饭");
    }

}
//但不是每个动物都会飞 会跑 会游泳 所以未来为实现这些方法 我们可以用接口来继承
interface IFlying{
    //抽象方法 默认public abstract
    void fly();
}

interface IRunning{
    void run();
}

interface ISwimming{
    void swim();
}

class Cat extends Animal implements IRunning{
    //如果父类有构造方法就应该先实现父类的构造方法
    public Cat(String name) {
        super(name);
    }
    //接着重写run的抽象方法
    @Override
    public void run() {
        System.out.println(this.name + "is cat 正在跑");
    }
}

class Dog extends Animal implements IRunning, ISwimming{
    public Dog(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(this.name + "is dog正在跑");
    }

    @Override
    public void swim() {
        System.out.println(this.name + "正在游泳");
    }
}

class Robot implements IRunning{
    @Override
    public void run() {
        System.out.println("机器人正在跑");
    }
}

class Duck extends Animal implements IRunning, ISwimming, IFlying{
    public Duck(String name) {
        super(name);
    }

    @Override
    public void fly() {
        System.out.println(this.name + "fly");
    }

    @Override
    public void run() {
        System.out.println(this.name + "run");
    }

    @Override
    public void swim() {
        System.out.println(this.name + "swim");
    }
}

public class Test2 {
    public static void walk(IRunning iRunning){
        iRunning.run();
    }
    public static void swim(ISwimming iSwimming){
        iSwimming.swim();
    }
    public static void fly(IFlying iFlying){
        iFlying.fly();
    }

    public static void main(String[] args) {
        Duck duck = new Duck("tanglaoya");
        swim(duck);
        fly(duck);
        walk(duck);
    }

    public static void main2(String[] args) {
        Dog dog = new Dog("哈哈");
        walk(dog);
        walk(new Dog("mimi2"));
        walk(new Cat("mimi1"));
        walk(new Robot());
    }

    public static void main1(String[] args) {
        Animal animal = new Cat("mimi");
        Animal animal1 = new Dog("mimi2");

        IRunning iRunning = new Dog("mimi2");
        ISwimming iSwimming = new Dog("mimi2");

        IRunning iRunning1 = new Cat("mimi");
    }
}
